package org.dairy.farms.dao.hibernate;

import org.dairy.farms.dao.CheckupDAO;
import org.dairy.farms.dao.generic.AbstractDAOImpl;
import org.dairy.farms.model.Checkup;
import org.dairy.farms.model.Livestock;
import org.hibernate.Criteria;
import org.hibernate.FetchMode;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: gduggira
 * Date: Jun 13, 2011
 * Time: 3:17:40 PM
 */
@Repository("checkupDao")
public class CheckupDAOImpl extends AbstractDAOImpl<Checkup, Long> implements CheckupDAO {

    public List<Checkup> getCheckupDetails(Long livestockId, int page, int start, int limit){
        Criteria criteria = basePersistence.getSession().createCriteria(Checkup.class);
        criteria.createCriteria("livestock")
                .add(Restrictions.eq("id",livestockId))
                .setFirstResult(start)
                .setMaxResults(limit)
                .setFetchMode("vaccine", FetchMode.SELECT)
                .setFetchMode("disease",FetchMode.SELECT);
        return criteria.list();
    }
}
